import Taro, { Component, request } from '@tarojs/taro'
import { View , Text , Image} from '@tarojs/components';
import { AtButton , AtTextarea , AtMessage } from 'taro-ui';
import { submitSuggest } from '../../util/api';
import './suggest.scss';
export default class Suggest extends Component {
    config = {
        navigationBarTitleText:"意见反馈",
    }
    constructor(){
        super(...arguments)
        this.state  = {
            value:"",
        }
    }
    handleChange (value) {
        this.setState({value})
    }
    submitData(){
        if(!this.state.value){
            Taro.atMessage({
                type:"error",
                'message':'请输入反馈内容'
            })
            return false
        }
        submitSuggest({content:this.state.value}).then( res => {
            if(res.code == 0){
                Taro.showModal({
                    title:"提示",
                    content:"提交成功"
                }).then( res => { Taro.switchTab({url:'/pages/tabuser/tabuser'}) })
            }else{
                Taro.showToast({title:res.msg,icon:"none"});
            }
        })
    }
    render(){
        return (
            <View className='suggest'>
                <View className='ipt-card'>
                    <AtTextarea
                        value={this.state.value}
                        onChange={this.handleChange.bind(this)}
                        maxLength={500}
                        placeholder='向我们提出宝贵的意见'
                        autoFocus
                        height={500}
                    />
                </View>
                <AtButton className='next-tip' type='primary' size='normal' onClick={this.submitData.bind(this)}>提交</AtButton>
                <AtMessage/>
            </View>
        )
    }
}